home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / scale_geom / simple.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-17  |  1.4 KB  |  59 lines

  1. /* simple.h: definitions of some simple, common constants and macros */
  2.  
  3. #ifndef SIMPLE_HDR
  4. #define SIMPLE_HDR
  5.  
  6. /* $Header: simple.h,v 1.6 89/04/26 11:32:51 ph Locked $ */
  7.  
  8. #include <stdio.h>
  9.  
  10. /* better than standard assert.h: doesn't gag on 'if (p) assert(q); else r;' */
  11. #ifndef NDEBUG
  12. #   define assert(p) if (!(p)) \
  13.     { \
  14.     fprintf(stderr, "Assertion failed: %s line %d: p\n", __FILE__, __LINE__); \
  15.     exit(1); \
  16.     } \
  17.     else
  18. # else
  19. #   define assert(p)
  20. #endif
  21.  
  22. #define str_eq(a, b)    (strcmp(a, b) == 0)
  23.  
  24. #ifndef MIN
  25. #define MIN(a, b)    ((a)<(b) ? (a) : (b))
  26. #endif
  27. #ifndef MAX
  28. #define MAX(a, b)    ((a)>(b) ? (a) : (b))
  29. #endif
  30. #ifndef ABS
  31. #define ABS(a)        ((a)>=0 ? (a) : -(a))
  32. #endif
  33.  
  34. #define SWAP(a, b, t)    {t = a; a = b; b = t;}
  35. #define LERP(t, a, b)    ((a)+(t)*((b)-(a)))
  36. #define ALLOC(ptr, type, n)  assert(ptr = (type *)malloc((n)*sizeof(type)))
  37. #define ALLOC_ZERO(ptr, type, n)  assert(ptr = (type *)calloc(n, sizeof(type)))
  38.  
  39. #define PI 3.14159265358979323846264338
  40. #define RAD_TO_DEG(x) ((x)*(180./PI))
  41. #define DEG_TO_RAD(x) ((x)*(PI/180.))
  42.  
  43. /* note: the following are machine dependent! (ifdef them if possible) */
  44. #define MINSHORT -32768
  45. #define MINLONG -2147483648
  46. #define MININT MINLONG
  47. #ifndef MAXINT    /* sgi has these in values.h */
  48. #   define MAXSHORT 32767
  49. #   define MAXLONG 2147483647
  50. #   define MAXINT MAXLONG
  51. #endif
  52.  
  53.  
  54. #ifdef hpux    /* hp's unix doesn't have bzero */
  55. #   define bzero(a, n) memset(a, 0, n)
  56. #endif
  57.  
  58. #endif
  59.